package com.winteam.Controler;

import com.winteam.Bean.RoomInfo;
import com.winteam.Bean.RoomType;
import com.winteam.dao.DbConnection;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoomSelect {

		public static List<RoomType> getRoomType(){
			String sql="SELECT * from r_tpye_info";
			ResultSet resultSet= DbConnection.query(sql);
			ArrayList<RoomType> list=new ArrayList<RoomType>();
			try {
				while (resultSet.next()) {
					RoomType r=new RoomType();
					r.setId(resultSet.getInt(1));
					r.setRoom_type(resultSet.getString(2));
					r.setR_price(resultSet.getInt(3));
					r.setR_hprice(resultSet.getInt(4));
					r.setR_bed(resultSet.getInt(5));

					list.add(r);
				}
		}catch (SQLException e) {

			e.printStackTrace();
		}

		return list;
}

		public static List<RoomInfo> getRoomInfo(){
			String sql= "select  a.r_rommber, c.r_type,b.r_state,c.r_bednumber,c.r_price from  room_info a , r_state_info b ,r_tpye_info c where b.id=a.r_state and c.id=a.r_type ";
			ResultSet resultSet=DbConnection.query(sql);
			ArrayList<RoomInfo> list=new ArrayList<RoomInfo>();
			try {
				Connection connection = DbConnection.getConnection();
				PreparedStatement preparedStatement = connection.prepareStatement(sql);
				ResultSet resultSet1 = preparedStatement.executeQuery();
				while (resultSet.next()){
					RoomInfo r = new RoomInfo();
					r.setR_rommber(resultSet.getString(1));
					r.setR_type(resultSet.getString(2));
					r.setR_state(resultSet.getString(3));
					r.setR_bednumber(resultSet.getInt(4));
					r.setR_price(resultSet.getInt(5));
					list.add(r);
				}
			}catch (SQLException e) {
			e.printStackTrace();
		}


		return list;
}

		public static Object[] getRoomComboBox(){
			String sql="SELECT r_type FROM roomtype";
			ResultSet resultSet=DbConnection.query(sql);
			ArrayList list=new ArrayList();
			try {
				while (resultSet.next()) {
					list.add(resultSet.getString(1));
				}
		}catch (SQLException e) {
			e.printStackTrace();
		}

		Object[] body=new Object[list.size()];
		for (int i = 0; i < list.size(); i++) {
			body[i]=list.get(i);
		}
		return body;
}		
}
